package com.usian.job;

import com.usian.pojo.Commodity;
import com.usian.service.CommodityService;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Date;
import java.util.List;

public class Myjob implements Job {

    @Autowired
    private CommodityService commodityService;

    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {

        //定时任务要执行的代码
        System.out.println("quzrtz要执行" + new Date());

        List<Commodity> commodityList = commodityService.querystatus();

        for (Commodity commodity : commodityList) {
            String cname = commodity.getCname();
            //查询审核名称
            String commodityName1 = commodityService.chaxun(cname);
            //如果为空审核数量
            if (commodityName1 == null || commodityName1 == "") {
                // 判断商品数量
                if (commodity.getInventory() < 100) {
                    //修改状态为审核通过4
                    commodityService.updateByCStart(commodity);
                } else {
                    commodityService.updateByCStartTo(commodity);
                    //失败原因商品 数量大于100
                    System.out.println("失败原因商品 数量大于100");
                }


            } else {
                commodityService.updateByCStartTo(commodity);
                // 失败原因商品名称重复
                System.out.println("失败原因商品名称重复");
            }
        }

        System.out.println(commodityList.toString());
    }
}
